package com.myBlog.controller;

import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.dto.RoleDTO;
import com.myBlog.domain.vo.PageVo;
import com.myBlog.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 查询出所有角色
     *
     * @return {@link ResponseResult}
     */
    @GetMapping("/listAllRole")
    public ResponseResult getListAllRole() {
        return roleService.getListAllRole();
    }

    /**
     * 分页条件查询
     *
     * @param pageNum
     * @param pageSize
     * @param roleName
     * @param status
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, String roleName, String status) {
        return roleService.list(pageNum, pageSize, roleName, status);
    }

    /**
     * 修改状态
     *
     * @param roleDTO
     * @return
     */
    @PutMapping("/changeStatus")
    public ResponseResult changStatus(@RequestBody RoleDTO roleDTO) {
        return roleService.changeStatus(roleDTO);
    }

    /**
     * 根据id查询权限信息
     *
     * @param roleId
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getRoleInfo(@PathVariable("id") Long roleId) {
        return roleService.getRoleInfo(roleId);
    }

    /**
     * 添加权限
     *
     * @param roleDTO
     * @return
     */
    @PostMapping
    public ResponseResult addRole(@RequestBody RoleDTO roleDTO) {
        return roleService.addRole(roleDTO);
    }

    /**
     * 修改权限
     *
     * @param roleDTO
     * @return
     */
    @PutMapping
    public ResponseResult updateRole(@RequestBody RoleDTO roleDTO) {
        return roleService.updateRole(roleDTO);
    }

    /**
     * 根据id删除权限
     *
     * @param roleId
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") Long roleId) {
        return roleService.delete(roleId);
    }
}
